<template>
	<x-border :title="viewModel.name" type="focus" icon="icon-5333-wubfen" v-if="viewModel">
		<div class="admin-task-edit">
			<el-form class="task-edit_form">
				<el-alert show-icon class="alert" :closable="false" type="success" :description="viewModel.intro" v-if="viewModel.intro"></el-alert>
				<el-form-item label="是否开启" :required="true">
					<el-switch v-model="viewModel.isEnable"></el-switch>
					<div class="edit_form-intro">任务开启以后可以会员员可在任务大厅中查看，只有开启的任务才可以执行</div>
				</el-form-item>
				<el-form-item label="开始时间" :required="true">
					<el-date-picker value-format="yyyy-MM-dd HH:mm:ss" v-model="viewModel.beginTime" type="datetime" placeholder="选择日期时间">
					</el-date-picker>
					<div class="edit_form-intro">任务的开始时间，不能小于当前时间</div>
				</el-form-item>
				<el-form-item label="结束时间" :required="true">
					<el-date-picker value-format="yyyy-MM-dd HH:mm:ss" v-model="viewModel.endTime" type="datetime" placeholder="选择日期时间">
					</el-date-picker>
					<div class="edit_form-intro">任务的开始时间，不能小于任务开始时间</div>
				</el-form-item>
				<el-form-item :label="item.title" v-for="(item,index) in viewModel.jobs" :key="index">
					<div class="form-switch_ul">
						<el-switch v-model="item.isEanble"></el-switch>
						<div class="form-switch_li" v-show="item.isEanble">
							<div class="form-switch_item form-switch_p">
								<div class="switch_item-lable">任务目标</div>
								<div class="switch_item-box">
									<el-input-number v-model="item.targetValue" size="small" :step="0.1" class="item-box_iput"></el-input-number>
								</div>
							</div>
							<div class="form-switch_item">
								<div class="switch_item-lable">奖励设置</div>
								<div class="switch_item-box">
									<div class="item-box_list" v-for="(reItem,reIndex) in item.rewards" :key="reIndex">
										<div class="item-box_ilable">{{reItem.moneyName}}</div>
										<el-input-number v-model="reItem.amount" size="small" :step="0.1" class="item-box_iput"></el-input-number>
									</div>
								</div>
							</div>
							<div class="edit_form-intro">
								<x-code>任务目标值大于0时，奖励获得才可生效</x-code>
							</div>
						</div>

					</div>

				</el-form-item>
				<el-form-item label="任务说明" :required="true">
					<x-json type="Tip" v-model="viewModel.tipList"></x-json>
					<div class="edit_form-intro">任务说明,会在前台任务大厅中显示相关的说明，建议不要少于2条</div>
				</el-form-item>
				<el-form-item label=" ">
					<el-button type="primary" @click="onSubmit">保存</el-button>
				</el-form-item>
			</el-form>
		</div>
	</x-border>
</template>
<script>
	export default {
		data() {
			return {
				viewModel: null,
				valu1: false
			}
		},
		mounted() {
			this.init()
		},
		methods: {
			async init() {
				this.viewModel = await this.$api.taskJobAdminView(this.$route.query.key)
			},
			async onSubmit() {
				var response = await this.$api.taskJobAdminSave(this.viewModel)
				if (response) {
					this.$ala.toMessage(response)
				}
			}
		}
	}
</script>
<style lang="scss">
	@import "./var.scss";
</style>